Sector diagrams and scatter diagrams - piechart and hexbin
The piechart
command is used to create pie charts for discrete variables. The hexbin
command creates an anonymizing plot diagram where the plot area is divided into hexagons which are colored based on how many plots there are in each area.
require no.ssb.fdb:30 as db
create-dataset demography
import db/INNTEKT_LONN 2020-01-01 as wage20
import db/INNTEKT_LONN 2015-01-01 as wage15
import db/BEFOLKNING_KJOENN as gender
import db/BEFOLKNING_FOEDSELS_AAR_MND as birthdate
import db/BOSATTEFDT_BOSTED 2020-01-01 as municipality
// Recode from municipality to county level
generate county = substr(municipality,1,2)
define-labels countystring '03' Oslo '11' Rogaland '15' 'Møre og Romsdal' '18' Nordland '30' Viken '34' Innlandet '38' 'Vestfold og Telemark' '42' Agder '46' Vestland '50' Trøndelag '54' 'Troms og Finnmark' '21' Spitsbergen '25' 'Education abroad' '99' Unknown
assign-labels county countystring
// Generate age per 2020
generate age = 2020 - int(birthdate/100)
// Piechart
// This is a nice way to present percentage distributions for discrete variables in a graphical way
drop if age < 16
piechart gender
piechart county
// Hexbinplot
// This is an anonymizing way of producing plot diagrams (best suited for continuous/metric variables), where the density in the plots is colored in a systematic way to reveal patterns in the distribution between two variables
hexbin wage20 wage15
hexbin wage20 wage15 if inrange(age,30,50)
hexbin wage20 wage15 if inrange(age,20,30)